#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e6 + 10, INF = 0x3f3f3f3f;

ll n;
string s;
vector<ll> A, B;

void solve()
{
    cin >> n >> s;
    s = " " + s;
    A.push_back(0);B.push_back(0);
    ll n2 = n * 2;
    for (ll i = 1;i <= n2;i++) {
        if (s[i] == 'A') A.push_back(i);
        else B.push_back(i);
    }
    vector<ll> C1, C2;
    C1.push_back(0);C2.push_back(0);
    for (ll i = 1;i <= n;i++) {
        C1.push_back(A[i]);
        C1.push_back(B[i]);
        C2.push_back(B[i]);
        C2.push_back(A[i]);
    }

    ll x1 = 0, x2 = 0;
    for (ll i = 1;i <= n2;i++) {
        x1 += abs(i - C1[i]);
        x2 += abs(i - C2[i]);
    }
    x1 /= 2, x2 /= 2;
    cout << min(x1, x2);
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}